//#include "stdafx.h"
#include "base_semaphore.h"

CBaseSemaphore::CBaseSemaphore()
{
	m_hSemaphore = INVALID_HANDLE_VALUE;
}
CBaseSemaphore::~CBaseSemaphore()
{
	if( m_hSemaphore != INVALID_HANDLE_VALUE )
	{
		CloseHandle( m_hSemaphore );
	}
}

bool CBaseSemaphore::CreateSemaphore(  uint32 nInitialCount, uint32 nMaximumCount, cstr_t lpszName/* = NULL*/ )
{
	m_hSemaphore = ::CreateSemaphore( NULL, nInitialCount, nMaximumCount, lpszName );
	return m_hSemaphore != INVALID_HANDLE_VALUE;
}
bool CBaseSemaphore::ReleaseSemaphore( uint32 nIncrease )
{
	return ::ReleaseSemaphore( m_hSemaphore, 1, NULL ) == TRUE;
}
uint32 CBaseSemaphore::WaiteSemaphore( uint32 nTimeout )
{
	DWORD nRet = WaitForSingleObject( m_hSemaphore, nTimeout );
	return nRet;
}